package com.mantisframework.core.page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 功能：翻页辅助bean 作者：马东东 时间:2010-11-11
 */
public class PageBean implements Serializable  {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** 当前页  默认为1*/
	private Integer currentPage = 1;
	/** 翻页单位 默认为5*/
	private Integer pageSize = 10;
	/** 总记录数 */
	private Integer totalRecord;
	/** 总页数 */
	@SuppressWarnings("unused")
	private Integer totalPage;
	/** 下一页 */
	@SuppressWarnings("unused")
	private Integer nextPage;
	/** 上一页 */
	@SuppressWarnings("unused")
	private Integer previousPage;
	/*** 翻页路径*/
	private String pagePath;
	/**翻页查询数据的开始位置*/
	
	/** 翻页记录集合 */
	@SuppressWarnings("unchecked")
	private List<?> datas = new ArrayList();
	/**统计bean实例*/
    private CensusBean  censusbean=new CensusBean();
	public PageBean() {
	}

	/**
	 * 带参数的够长方法
	 * @param currentPage 当前页
	 * @param pageSize 翻页单位
	 */
	public PageBean(Integer currentPage, Integer pageSize) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
	}


	/**
	 * 翻页辅助bean构造方法
	 * 
	 * @param currentPage
	 *            当前页
	 * @param pageSize
	 *            翻页单位
	 * @param totalRecord
	 *            总记录数
	 * @param datas
	 *            翻页记录集合
	 */
	public   PageBean(Integer currentPage, Integer pageSize, Integer totalRecord,
			List<?> datas) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		this.datas = datas;
	}
	public   PageBean(Integer currentPage, Integer pageSize, Integer totalRecord,
			List<?> datas,String pagePath) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		this.datas = datas;
		this.pagePath=pagePath;
	}
	
	/**
	 * 
	 * @param currentPage 当前页
	 * @param pageSize 翻页单位
	 * @param totalRecord 总记录数
	 */
	public PageBean(Integer currentPage, Integer pageSize, Integer totalRecord) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
	}

	


	public PageBean(Integer currentPage, Integer pageSize, String pagePath) {
		this.currentPage = currentPage;
		this.pageSize = pageSize;
		this.pagePath = pagePath;
	}
	
	public  int getIndex(){
		
		return (this.currentPage-1)*this.pageSize;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(Integer totalRecord) {
		this.totalRecord = totalRecord;
	}

	public Integer getNextPage() {
		return currentPage >= this.getTotalPage() ? this.getTotalPage()
				: (currentPage + 1);
	}

	public void setNextPage(Integer nextPage) {
		this.nextPage = nextPage;
	}

	public Integer getPreviousPage() {
		return currentPage <= 1 ? 1 : (currentPage - 1);
	}

	public void setPreviousPage(Integer previousPage) {
		this.previousPage = previousPage;
	}

	public List<?> getDatas() {
		return datas;
	}

	public void setDatas(List<?> datas) {
		this.datas = datas;
	}

	public Integer getTotalPage() {
		if(totalRecord==0){
			return 1;
		}else{
		return (totalRecord + pageSize - 1) / pageSize;
		}
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	public String getPagePath() {
		return pagePath;
	}

	public void setPagePath(String pagePath) {
		this.pagePath = pagePath;
	}

    /**统计 get bean 作者：马东东*/
	public CensusBean getCensusbean() {
		return censusbean;
	}

	 /**统计set bean 作者：马东东*/
	public void setCensusbean(CensusBean censusbean) {
		this.censusbean = censusbean;
	}
    



}
